package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.CountryDao;
import com.pojo.Country;
import com.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CountryService extends ServiceImpl<CountryDao, Country> {

    @Autowired
    private CountryDao countryDao;

    /**
     * 分页查询国家
     * @param name  关键字
     * @param page  页面
     * @param limit  条数
     * @return
     */
    public IPage selectCountrys(int page, int limit, String name) {
        Page p = new Page(page, limit);
        QueryWrapper<Country> query = new QueryWrapper();

        if(StringUtil.isNotNull(name)) {
            query.and(wrapper->wrapper.like("country_zh_name" , name).or().like("country_en_name",name));
        }
        IPage iPage = countryDao.selectPage(p, query);
        return iPage;
    }
}
